#include "pagerfidtemp.h"

PageRFIDTemp::PageRFIDTemp(QWidget *parent) : QWidget(parent)
{
    resize(1024, 548);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    for(int i=0; i<4; ++i)
    {
        QLabel *carNumLabel = new QLabel(QString().setNum(i+1),this);
        carNumLabel->setStyleSheet("color:white;font-size: 18pt; font-family: arial");
        carNumLabel->setGeometry(30, 80+75*i, 15, 60);

        titleList.append(new QLabel(this));
        titleList.at(i)->setGeometry(60, 80+75*i, 900, 60);
        titleList.at(i)->setStyleSheet("border: 1px solid white;color:white;font-size: 18pt; font-family: arial");
    }

    for(int i=0; i<4; ++i)
    {
        for(int j=0; j<12; ++j)
        {
            if(i==0)
            {
                QLabel* tagID = new QLabel(this);
                tagID->setStyleSheet("color:white;font-size: 18pt; font-family: arial");
                tagID->setGeometry(95+70*j,40+75*i, 60, 40);
                tagID->setAlignment(Qt::AlignCenter);
                tagID->setText(j/6?QString("B%1").arg(j%6+1):QString("A%1").arg(j%6+1));
            }
            QLabel* tag = new QLabel(this);
            tag->setStyleSheet(LabelGrayStyle);
            tag->setGeometry(95+70*j,90+75*i, 60, 40);
            tag->setAlignment(Qt::AlignCenter);
            tag->setText("-40");
            m_lRFIDTagList.append(tag);
        }
    }

    InitHelp();

    backBtn = new QPushButton(this);
    backBtn->setStyleSheet(SideNaviBtnStyle);
    backBtn->setGeometry(900,480,100,50);
    backBtn->setText("返回");
    connect(backBtn,SIGNAL(clicked()),this,SIGNAL(returnToMaintMenu()));
}

void PageRFIDTemp::setTempValue(int index, int val)
{
    if(index >= m_lRFIDTagList.length())
        return;
    if(val == 0xFF)
        m_lRFIDTagList[index]->setText("?");
    else
        m_lRFIDTagList[index]->setText(QString().setNum(val-40));
}

void PageRFIDTemp::setTempStat(int index, int stat)
{
    if(index >= m_lRFIDTagList.length())
        return;
   switch(stat)
   {
   case 0:
       m_lRFIDTagList[index]->setStyleSheet(LabelGrayStyle);
       break;
   case 1:
       m_lRFIDTagList[index]->setStyleSheet(LabelBlueStyle);
       break;
   case 2:
       m_lRFIDTagList[index]->setStyleSheet(LabelRedStyle);
       break;
   case 3:
       m_lRFIDTagList[index]->setStyleSheet(LabelYellowStyle);
       break;
   case 4:
       m_lRFIDTagList[index]->setStyleSheet(LabelOrangeStyle);
       break;
   case 5:
       m_lRFIDTagList[index]->setStyleSheet(LabelWhiteStyle);
       break;
   default:
       m_lRFIDTagList[index]->setStyleSheet(LabelGrayStyle);
       break;
   }
}

void PageRFIDTemp::InitHelp()
{
    //帮助
    QLabel *helpUnknown = new QLabel(this);
    helpUnknown->setStyleSheet(LabelGrayStyle);
    helpUnknown->setGeometry(150 ,400, 60, 40);
    QLabel *helpUnknownCH = new QLabel(this);
    helpUnknownCH->setAlignment(Qt::AlignCenter);
    helpUnknownCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpUnknownCH->setGeometry(150+60 ,400, 60, 40);
    helpUnknownCH->setText("未知");

    QLabel *helpIso = new QLabel(this);
    helpIso->setStyleSheet(LabelBlueStyle);
    helpIso->setGeometry(150+60*2,400, 60, 40);
    QLabel *helpIsoCH = new QLabel(this);
    helpIsoCH->setAlignment(Qt::AlignCenter);
    helpIsoCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpIsoCH->setGeometry(150+60*3,400, 60, 40);
    helpIsoCH->setText("屏蔽");

    QLabel *helpFlt = new QLabel(this);
    helpFlt->setStyleSheet(LabelRedStyle);
    helpFlt->setGeometry(150+60*4,400, 60, 40);
    QLabel *helpFltCH = new QLabel(this);
    helpFltCH->setAlignment(Qt::AlignCenter);
    helpFltCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpFltCH->setGeometry(150+60*5,400, 60, 40);
    helpFltCH->setText("故障");

    QLabel *helpWarn = new QLabel(this);
    helpWarn->setStyleSheet(LabelYellowStyle);
    helpWarn->setGeometry(150+60*6,400, 60, 40);
    QLabel *helpWarnCH = new QLabel(this);
    helpWarnCH->setAlignment(Qt::AlignCenter);
    helpWarnCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpWarnCH->setGeometry(150+60*7,400, 60, 40);
    helpWarnCH->setText("报警");

    QLabel *helpPreWarn = new QLabel(this);
    helpPreWarn->setStyleSheet(LabelOrangeStyle);
    helpPreWarn->setGeometry(150+60*8,400, 60, 40);
    QLabel *helpPreWarnCH = new QLabel(this);
    helpPreWarnCH->setAlignment(Qt::AlignCenter);
    helpPreWarnCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpPreWarnCH->setGeometry(150+60*9,400, 60, 40);
    helpPreWarnCH->setText("预警");

    QLabel *helpNormal = new QLabel(this);
    helpNormal->setStyleSheet(LabelWhiteStyle);
    helpNormal->setGeometry(150+60*10,400, 60, 40);
    QLabel *helpNormalCH = new QLabel(this);
    helpNormalCH->setAlignment(Qt::AlignCenter);
    helpNormalCH->setStyleSheet("font:15pt 'Arial';color:white;");
    helpNormalCH->setGeometry(150+60*11,400, 60, 40);
    helpNormalCH->setText("正常");
}
